import torch
import csv
import numpy as np
def func1():
    points = torch.randn(5,2)
    print(points)
    print(points[2:,:1])
    torch.save(points, "a.txt")
    print(torch.load("a.txt"))
def func2():
    
    wine_path = "/Users/wangshuguan/Downloads/winequality-white.csv"
    #跳过第一行
    wine_numpy = np.loadtxt(wine_path, dtype=np.float32, delimiter=";", skiprows = 1)
    # print(wine_numpy)
    
    
    col_list = next(csv.reader(open(wine_path), delimiter=';'))
    # print(col_list)
    
    datas = torch.from_numpy(wine_numpy)
    # print(datas)
    # print(datas[:-1,:])
    # print(datas[:,-1].long())
    target = datas[:,-1].long()
    print(target)
    # print(target.numpy().shape)
    target_onehot = torch.zeros(target.shape[0], 10)
    target_onehot.scatter_(1, target.unsqueeze(1), 1.0)
    print(target_onehot)
    print(target.unsqueeze(1))
    # print(target_onehot[0])
    # print(target_onehot[-2:])
    
    
    
def func3():
    
    wine_path = "/Users/wangshuguan/Downloads/winequality-white.csv"
    #跳过第一行
    wine_numpy = np.loadtxt(wine_path, dtype=np.float32, delimiter=";", skiprows = 1)
    col_list = next(csv.reader(open(wine_path), delimiter=';'))
    print(col_list)
    datas = torch.from_numpy(wine_numpy)
    # print(datas)
    # print(datas[1, :])
    data_mean = torch.mean(datas, dim=0)
    [print(x) for x in data_mean.numpy()]
    data_var = torch.var(datas, dim=0)
    data_normalized = (datas - data_mean) / torch.sqrt(data_var)
    print(data_normalized[1])
func3()
